package com.letoken.platform.repo.app.redis;

import com.letoken.platform.pub.constant.RedisKeyConstant;
import com.letoken.platform.pub.util.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * @version 1.0
 * @author： letokenlabs
 * @date： 2021/11/24 9:55
 * 登录次数
 */
@Slf4j
public class AppExReportMd5Redis {
    private StringRedisTemplate stringRedisTemplate;
    private SetOperations<String, String> valueOps;

    private AppExReportMd5Redis() {
        stringRedisTemplate = BeanUtil.getBean(StringRedisTemplate.class);
        this.valueOps = stringRedisTemplate.opsForSet();
    }

    private enum Singleton {
        INSTANCE;
        private AppExReportMd5Redis instance;

        // JVM会保证此方法绝对只调用一次
        Singleton() {
            instance = new AppExReportMd5Redis();
        }
    }

    String cacheKey = RedisKeyConstant.APP_EX_REPORT_MD5;

    public static AppExReportMd5Redis me() {
        return AppExReportMd5Redis.Singleton.INSTANCE.instance;
    }

    // 新增md5
    public void add(String md5) {
        this.valueOps.add(cacheKey,md5);
    }

    // 是否存在
    public boolean isMember(String md5) {
        return Boolean.TRUE.equals(this.valueOps.isMember(cacheKey, md5));
    }

}
